import chisel3.stage.ChiselGeneratorAnnotation
import firrtl.options.TargetDirAnnotation

object TopMainCounter extends App{
  def parseArgs(key: String, args: Array[String]) : String = {
    var value = ""
    for(arg <- args) {
      if(arg.startsWith(key + "=") == true){
        value = arg
      }
    }
    require(value != "")
    value.substring(key.length + 1);
  }

  val top = parseArgs("TopModule", args)
  val max = parseArgs("MAX", args)

  if(top == "Counter"){
    //chisel3.Driver.execute(args, () => new Counter(8))

    (new chisel3.stage.ChiselStage).emitVerilog(new Counter(max.toInt), args)
  }
}